<template>
	<view class="wrapper">
		<view class="common-view">
			<video style="width: 660rpx;" ref="media" controls="true" :src="videoUrl" :autoplay="true" :controls="true"
				:webkit-playsinline="true" :x-webkit-airplay="true" playsinlin>
				您的浏览器不支持 video 标签。
			</video>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		HOST
	} from "../../static/js/const";

	// let videoUrl = ref("rtmp://ns8.indexforce.com/home/mystream");
	let videoUrl = ref("");

	onLoad((options) => {
		uni.request({
			url: `${HOST}/zxw/spjk/getPlayUrl`, // 请求的接口地址
			method: 'POST',
			data: {
				deviceId: options.equipmentCode,
			},
			header: {
				'content-type': 'application/json', // 默认值，也可以根据接口要求修改
				'Authorization': 'Bearer ' + uni.getStorageSync('accessToken')
			},
			success: (res) => {
				console.log("getPlayUrl");
				console.log(res);
				// {
				//     "ResponseStatus": {
				//         "LocalTime": "2025-05-23 10:08:51",
				//         "RequestURL": "/cms/rest/GetPlayUrl/43112910001320000001",
				//         "StatusCode": "0"
				//     },
				//     "PlayUrl": "http://192.168.66.100:80/liv731000000020101-___/liv731000000020101-___.m3u8?ty=live&un=cy&ui=06100306669&ci=731000000020101&st=1747966131&vt=7200&r=2041474354&Sign=6f778fe37e8ad89f046969c4052e7a0e",
				//     "ControlUrl": "http://192.168.66.100:80/liv731000000020101-___/liv731000000020101-___.ctrl?ty=live&un=cy&ui=06100306669&ci=731000000020101&st=1747966131&vt=7200&r=2041474354&Sign=6f778fe37e8ad89f046969c4052e7a0e"
				// }
				
				// {
				//     "status": "OK",
				//     "code": null,
				//     "flag": true,
				//     "message": "",
				//     "data": {
				//         "ResponseStatus": {
				//             "LocalTime": "2025-05-23 10:10:23",
				//             "RequestURL": "/cms/rest/GetPlayUrl/43010000001320000001",
				//             "StatusCode": "990106"
				//         }
				//     }
				// }
				if (res.data.PlayUrl) {
					videoUrl.value = res.data.PlayUrl.replace(/192\.168\.66\.100:80/g,
						'111.23.104.94:18085');
				} else {
					uni.showToast({
						title: "无播放视频",
						icon: "error"
					});
				}
			},
			fail: (err) => {
				console.error('请求失败', err);
				uni.showToast({
					title: "连接失败",
					icon: "error"
				});
			}
		});
	})
</script>

<style lang="scss" scoped>
	.container {
		height: 100vh;
		padding: 0 $myuni-spacing-super-lg;
		// background: #D4ECFF;
		background: linear-gradient(to bottom, #d8ecff, #e3e9f4, #cadbf7);
		// background-color: #d8ecff;
		overflow: auto;
	}
</style>